x86/xstate: Fix latent bugs in expand_xsave_states()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Mon, 12 Sep 2016 09:30:00 +0000 (10:30 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Tue, 13 Sep 2016 09:44:03 +0000 (10:44 +0100)
commit40db977eea1e57fc33cd478d60678c71b4328eb0
tree5af0f9ed4eccf34484e66d890503639a9b7fbd8d
parent6accc5f1af1b51ea4fefcddce72db4e795f580c3
x86/xstate: Fix latent bugs in expand_xsave_states()

Without checking the size input, the memcpy() for the uncompressed path might
read off the end of the vcpu's xsave_area.  Both callers pass the approprite
size, so hold them to it with a BUG_ON().

The compressed path is currently dead code, but its attempt to avoid leaking
uninitalised data was incomplete.  Work around this by zeroing the whole rest
of the buffer before decompression.

The loop skips all bits which aren't set in xstate_bv, meaning that the
memset() was dead code.  The logic is more obvious with get_xsave_addr()
expanded inline, allowing for quite a lot of simplification, including all the
NULL pointer logic.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <JBeulich@suse.com>
xen/arch/x86/xstate.c